MovieViewer = null;

_MovieViewer = function() {
}

_MovieViewer.prototype = {
	SearchMovie : function() {
		var _ShowMovie = ClientCommandsManager.Get("GetMovies");
		_ShowMovie.RequiredName = $('#MovieSearchName').val();
		CloakManager.OnCloak(false, true);
		ClientCommandsManager.Execute(_ShowMovie, this.SuccessHandler, null);
	},
	ShowFirstTen : function() {
		var _ShowFirstTen = ClientCommandsManager.Get("GetFirstTenMovies");
		CloakManager.OnCloak(false, true);
		ClientCommandsManager.Execute(_ShowFirstTen, this.SuccessHandler, null);
	},
	SuccessHandler : function(data, status, request) {
		CloakManager.OffCloak(true, true);
		if (data) {
			var s = "";
			for (i = 0; i < data.length; i++) {
				s += "<p>"
				s += "<b>Name: </b>" + data[i].Name;
				s += "<br />";
				s += "<i>Description: </i>" + data[i].MovieDescription;
				s += "<br />";
				s += "<i>Genre: </i>" + data[i].Genre;
				s += "<br />";
				s += "<i>Actors: </i>" + data[i].Actors;
				s += "<br />";
				s += "<i>Rating (IMDB): </i>" + data[i].RatingIMDB;
				s += "<br />";
				s += "<i>Rating: </i>" + data[i].Rating;
				s += "<br />";
				s += "<i>Rating (MPAA): </i>" + data[i].RatingMPAA;
				s += "<br />";
				s += "<i>Cover: </i>" + data[i].Cover;
				s += "<br />";
				s += "<i>Profit: </i>";
				s += "<br />";
				s += "...in Russia:" + data[i].ProfitInRussia;
				s += "<br />";
				s += "...in USA:" + data[i].ProfitInUSA;
				s += "<br />";
				s += "...in Europe:" + data[i].ProfitInEurope;
				s += "<br />";
				s += "...in other countries:" + data[i].ProfitInOtherCountries;
				s += "<br />";
				s += "...from TV:" + data[i].ProfitFromTV;
				s += "<br />";
				s += "...from DVD:" + data[i].ProfitFromDVD;
				s += "</p>";
			}
			document.getElementById("searchOutput").innerHTML = s;

		} else {
			var nItem = NotificationManager.CreateNotification(
					"Error. No one movie found...", [ "error" ]);
			NotificationManager.ShowMessages([ nItem ]);
			this.ShowFirstTen();
		}
	}
}
